package com.starview.star.compiler.wff;

import com.starview.platform.data.IValue;
import com.starview.star.compiler.ast.Apply;
import com.starview.star.compiler.ast.BigDecimalLiteral;
import com.starview.star.compiler.ast.BooleanLiteral;
import com.starview.star.compiler.ast.CharLiteral;
import com.starview.star.compiler.ast.FloatLiteral;
import com.starview.star.compiler.ast.IAbstract;
import com.starview.star.compiler.ast.IAbstractVisitor;
import com.starview.star.compiler.ast.IntegerLiteral;
import com.starview.star.compiler.ast.LongLiteral;
import com.starview.star.compiler.ast.Name;
import com.starview.star.compiler.ast.StringLiteral;

public class Complexity implements IAbstractVisitor
{
  private int count = 0;

  private Complexity()
  {
  }

  public static int complexity(IAbstract term)
  {
    Complexity comp = new Complexity();
    term.accept(comp);
    return comp.count;
  }

  @Override
  public void visitApply(Apply app)
  {
    count++;
    for (IValue arg : app.getArgs())
      ((IAbstract) arg).accept(this);
  }

  @Override
  public void visitBooleanLiteral(BooleanLiteral lit)
  {
    count++;
  }

  @Override
  public void visitCharLiteral(CharLiteral lit)
  {
    count++;
  }

  @Override
  public void visitFloatLiteral(FloatLiteral flt)
  {
    count++;
  }

  @Override
  public void visitIntegerLiteral(IntegerLiteral lit)
  {
    count++;
  }

  @Override
  public void visitLongLiteral(LongLiteral lit)
  {
    count++;
  }

  @Override
  public void visitBigDecimal(BigDecimalLiteral lit)
  {
    count++;
  }

  @Override
  public void visitName(Name name)
  {
    count++;
  }

  @Override
  public void visitStringLiteral(StringLiteral str)
  {
    count++;
  }

}
